package com.sali.b_design_pattern.a_simple_factory_pattern.lesson_01.factory;

import com.sali.b_design_pattern.a_simple_factory_pattern.lesson_01.product.ICourse;
import com.sali.b_design_pattern.a_simple_factory_pattern.lesson_01.product.impl.AppCourse;
import com.sali.b_design_pattern.a_simple_factory_pattern.lesson_01.product.impl.GoCourse;
import com.sali.b_design_pattern.a_simple_factory_pattern.lesson_01.product.impl.JavaDesignCourse;

/**
 * @description:
 * @date: 2022/11/13 17:46.
 * @version: 1.0
 */
public class CourseFactory {

    /**
     * description: 当一个方法的返回值是父类或接口时，就会引发多态和向下造型。
     * 即返回值是父类和接口时，可接收任何一切子类和自己本身
     **/
    public static ICourse getInstance(int flag) {
        if (flag == 1) {
            return new JavaDesignCourse();
        } else if (flag == 2) {
            return new GoCourse();
        } else if (flag == 3) {
            return new AppCourse();
        }
        return null;
    }

}
